#pragma once

#include <QScopedPointer>
#include <QTableView>

class LogViewPrivate;
class LogView : public QTableView
{
    Q_OBJECT
public:
    enum State { Normal = 0, Error, Progress, Success, Failure };
    enum Cols { Status = 0, Contents, Count };
    struct Colors {
        static QColor Null()  { return QColor::fromRgb(QRgb(0x00000000)); }
        static QColor Black() { return QColor::fromRgb(QRgb(0xff000000)); }
        static QColor White() { return QColor::fromRgb(QRgb(0xffffffff)); }
        static QColor Green() { return QColor::fromRgb(QRgb(0xff11d116)); }
        static QColor Red()   { return QColor::fromRgb(QRgb(0xffed1515)); }
    };

    LogView(QWidget *parent = nullptr);
    ~LogView();

    bool is_progress();

public Q_SLOTS:
    void reset_default();
    void clear();
    QString addline(const QString &content, State status = State::Normal, const QVariant &data = QVariant(), QColor color = Colors::Null(), QFont::Weight weight = QFont::Weight::Normal, QFont::Style style = QFont::Style::StyleNormal);
    QString addnormal(const QString &content);
    QString adderror(const QString &contents);
    QString addprogress(const QString &content);
    QString addsuccess(const QString &content);
    QString addfailure(const QString &content);
    QString updateprogress(int progress, const QString &contents);

private:
    const QScopedPointer<LogViewPrivate> d_ptr;
    Q_DECLARE_PRIVATE(LogView)
};
